// http://www.cnblogs.com/TomXu/archive/2012/02/24/2353434.html
var tree = {};
tree.decorate = function(){
	console.log('Make sure the tree won\'t fall');
};

tree.getDecorator = function(deco){
	tree[deco].prototype = this;
	console.log(deco);
	console.log(tree[deco]);
	return new tree[deco];
};


tree.RedBalls = function(){
	this.decorate = function(){
		this.RedBalls.prototype.decorate();
		console.log('Put on some red balls');
	}
};

tree.BlueBalls = function(){
	this.decorated = function(){
		// this.BlueBalls.prototype.decorate();// 第1步：先执行原型的decorate方法，也就是tree.decorate()
		console.log('Add blue balls');
	}
}

tree.Angel = function(){
	this.decorate = function(){
		this.Angel.prototype.decorate();
		console.log('An angel on the top');
	}
}

tree = tree.getDecorator('BlueBalls');
tree = tree.getDecorator('Angel');
tree = tree.getDecorator('RedBalls');
console.log(tree);
tree.decorate();
